/**
 * Copyright 2011 Joe Choi, All rights reserved.
 */
package tao.data.structure.tree;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * This basic implementation of Trees interface
 * 
 * @author Joe Choi
 */
public abstract class AbstractTrees<V> implements Trees<V> {
	@Override
	public int size() {
		return(getTrees().size());
	}
	
	@Override
	public Iterator<Tree<V>> iterator() {
		return (getTrees().iterator());
	}	
	
	@Override
	public String toString() {
		return(getTrees().toString());
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == null || (!(obj instanceof AbstractTrees))) return(false);
		AbstractTrees<?> other = (AbstractTrees<?>) obj;
		return(this.getTrees().equals(other.getTrees()));
	}
	
	@Override
	public int hashCode() {
		return(getTrees().hashCode());
	}
	
	@Override
	public List<Tree<V>> generalize() {
		return (new ArrayList<Tree<V>>(getTrees()));
	}
	
	@Override
	public List<V> generalizeValue() {
		List<V> values = new ArrayList<V>();
		for(Tree<V> t : getTrees()) values.add(t.getValue());
		return(values);
	}
	
	protected abstract List<Tree<V>> getTrees();
}
